import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:text_pixel/src/bean/bean.dart';

import '../platform_interface/text_pixel_platform_interface.dart';

/// An implementation of [TextPixelPlatform] that uses method channels.
class MethodChannelTextPixel extends TextPixelPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('text_pixel');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

  @override
  Future<ColorResult> getTextColors({
    required int width,
    required int height,
    required List<Map<String, dynamic>> textList,
    required int fontSize,
    required int maxFrames,
    required int maxLines,
    required bool continuousPaint,
    required bool horizontalCenter
  }) async{
    Map<String, dynamic>? map = (await methodChannel.invokeMethod<Map<dynamic, dynamic>>('getTextColors', {
      'width': width,
      'height': height,
      'textList': textList,
      'fontSize': fontSize,
      'maxFrames': maxFrames,
      'maxLines': maxLines,
      'continuousPaint': continuousPaint,
      'horizontalCenter': horizontalCenter
    }))?.cast<String, dynamic>();
    return ColorResult.fromMap(map);
  }
}
